package com.ruoyi.project.lesson.block.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.lesson.block.domain.LessonBlock;
import com.ruoyi.project.lesson.block.mapper.LessonBlockMapper;
import com.ruoyi.project.lesson.block.service.ILessonBlockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程板块Service业务层处理
 *
 * @author shixiangwen
 * @date 2020-12-07
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class LessonBlockServiceImpl implements ILessonBlockService {

    @Autowired
    private LessonBlockMapper lessonBlockMapper;

    @Autowired
    ICommonService commonService;

    /**
     * 查询课程板块
     *
     * @param id 课程板块ID
     * @return 课程板块
     */
    @Override
    public LessonBlock selectLessonBlockById(Long id) {
        return lessonBlockMapper.selectLessonBlockById(id);
    }

    /**
     * 查询课程板块列表
     *
     * @param lessonBlock 课程板块
     * @return 课程板块
     */
    @Override
    public List<LessonBlock> selectLessonBlockList(LessonBlock lessonBlock) {
        return lessonBlockMapper.selectLessonBlockList(lessonBlock);
    }

    /**
     * 新增课程板块
     *
     * @param lessonBlock 课程板块
     * @return 结果
     */
    @Override
    public int insertLessonBlock(LessonBlock lessonBlock) {
        lessonBlock.setCreatedTime(DateUtils.getNowDate());
        return lessonBlockMapper.insertLessonBlock(lessonBlock);
    }

    /**
     * 修改课程板块
     *
     * @param lessonBlock 课程板块
     * @return 结果
     */
    @Override
    public int updateLessonBlock(LessonBlock lessonBlock) {
        return lessonBlockMapper.updateLessonBlock(lessonBlock);
    }

    /**
     * 删除课程板块对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLessonBlockByIds(String ids) {
        return lessonBlockMapper.deleteLessonBlockByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程板块信息
     *
     * @param id 课程板块ID
     * @return 结果
     */
    @Override
    public int deleteLessonBlockById(Long id) {
        return lessonBlockMapper.deleteLessonBlockById(id);
    }

    @Override
    public int getMaxSort() {
        return commonService.selectTableColumnMaxValue("lesson_block", "sort") + 1;
    }
}
